//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.ComponentModel;
using System.Text;
using Microsoft.Research.ScientificWorkflow.TridentUtilities;
using System.Windows.Media.Imaging;
using System.Collections.Generic;
using SR = Microsoft.Research.DataLayer;

namespace WorkflowApplicationModels
{
    /// <summary>
    /// The Machine model.
    /// </summary>
    public class MachineModel : INotifyPropertyChanged
    {
        #region Private Variables

        private string name;

        private Guid id;

        private bool isInteractive;

        #endregion Private Variables

        #region Public Properties

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.name = value;
                this.RaisePropertyChanged("Name");
            }
        }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public Guid Id
        {
            get
            {
                return this.id;
            }

            set
            {
                this.id = value;
                this.RaisePropertyChanged("Id");
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is interactive.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is interactive; otherwise, <c>false</c>.
        /// </value>
        public bool IsInteractive
        {
            get
            {
                return this.isInteractive;
            }

            set
            {
                this.isInteractive = value;
                this.RaisePropertyChanged("IsInteractive");
            }
        }

        #endregion Public Properties

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Raises the property changed.
        /// </summary>
        /// <param name="name">The name.</param>
        protected void RaisePropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MachineModel"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public MachineModel(string name)
        {
            this.Name = name;
            this.Id = Guid.NewGuid();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MachineModel"/> class.
        /// </summary>
        /// <param name="machine">The machine.</param>
        public MachineModel(SR.Machine machine)
        {
            this.Name = machine.Name;
            this.Id = (machine as SR.IObject).ID;
            this.IsInteractive = machine.IsInteractiveExecution;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return this.Name;
        }

        /// <summary>
        /// Determines whether teh current node is valid machine node or not.
        /// </summary>
        /// <returns>
        /// 	<c>true</c> if [is valid node]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsValid()
        {
            return !this.Name.Equals(WorkflowApplicationResourceManager.GetString("SelectNodeText"), StringComparison.OrdinalIgnoreCase);
        }

        #endregion Public Methods
    }
}
